home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / RCSC.ZIP / LIB51 / ITOX.C < prev    next >
Text File  |  1997-01-12  |  619b  |  24 lines

  1. /*
  2. ** itox -- converts nbr to hex string of length sz
  3. **         right adjusted and blank filled, returns str
  4. **
  5. **        if sz > 0 terminate with null byte
  6. **        if sz = 0 find end of string
  7. **        if sz < 0 use last byte for data
  8. */
  9. itox(nbr, str, sz)  int nbr;  char str[];  int sz;  {
  10.   int digit, offset;
  11.   if(sz>0) str[--sz]=0;
  12.   else if(sz<0) sz = -sz;
  13.   else while(str[sz]!=0) ++sz;
  14.   while(sz) {
  15.     digit=nbr&15; nbr=(nbr>>4)&4095;
  16.     if(digit<10) offset=48; else offset=55;
  17.     str[--sz]=digit+offset;
  18.     if(nbr==0) break;
  19.     }
  20.   while(sz) str[--sz]=' ';
  21.   return str;
  22.   }
  23.  
  24.